<?php

require_once( '../../libs/smarty.inc' );

require_once( '../../libs/smt_variables.php' );

require_once( '../../libs/Class_DB.php' );

require_once( '../../libs/Class_ERROR.php' );

require_once( '../../libs/login.inc.php' );



define('PAGE_MAX', 20 );



if( !in_array( "K", $_SESSION['ADMIN_LOGIN']['AUTH_CD'] ) ) exit;



$forms = $_GET;



if( isset( $forms['page'] ) && is_numeric( $forms['page'] ) ){

	$page['current'] = $forms['page'];

	$st = ( $page['current'] -1 ) * PAGE_MAX;

}else{

	$page['current'] = 1;

	$st = 0;

}





$db = new Class_DB;



$sql = "SELECT * FROM D_BLOG";

$cnt_sql = "SELECT COUNT(*) AS cnt FROM D_BLOG";



$sql .=  sprintf(" ORDER BY blog_date DESC, u_date DESC LIMIT %u, %u", $st, PAGE_MAX );



// 件数取得・ページング

$db->query( $cnt_sql );

$row = $db->fetch();

$page['cnt'] = $row['cnt'];

$page['end'] = floor( $page['cnt'] / PAGE_MAX );

if( $page['cnt'] % PAGE_MAX ) $page['end']++;



for( $i = 1; $i <= $page['end']; $i++ ){

	$page['paging'][] = $i;

}



$page['item'] = PAGE_MAX;





$db->query( $sql );



while( $row = $db->fetch() ){

	$data[] = $row;

}





$smarty->assign('status',	array( 0 => '非公開', 1 => '公開' ));

$smarty->assign('page', $page);

if( isset($data) ) $smarty->assign('data', $data);

if( isset($forms) ) $smarty->assign('forms', $forms);

$smarty->display('web-admin/blog_index.html');



?>